<template>
	<view class="product_details">
		<view class="product_details_box">
			<view class="product_details_box_top">
				<image :src="res.thumb" mode=""></image>
			</view>
			<view class="product_details_box_title">
				<view class="product_details_box_title_name">
					{{res.title}}
				</view>
				<view class="product_details_box_title_marketprice">
					<p>￥{{res.marketprice}}</p>
					<view class="">
						999+人付款
					</view>
				</view>
			</view>
			<view class="product_details_box_commodity_details">
				<u-divider text="商品详情" textColor="#ff0000" lineColor="#ff0000"></u-divider>
				<view class="product_details_box_commodity_details_box" v-html='res.content'>

				</view>
			</view>
			<view class="product_details_box_goumai">
				<view class="product_details_box_goumai_box" @click="show = !show">
					立即购买
				</view>
			</view>
		</view>

		<u-popup :show="show" mode="bottom" :closeable='true' :closeOnClickOverlay='true' @close="close" @open="open">
			<view class="popup_box">
				<view class="popup_box_goods">
					<image :src="res.thumb" mode="widthFix"></image>
					<view class="popup_box_goods_text">
						<span></span>
						<p>￥{{res.marketprice}}</p>
					</view>
				</view>
				<view class="number">
					<p>数量：</p>
					<u-number-box v-model="num" @change="valChange"></u-number-box>
				</view>
				<view class="popup_box_goumai">
					<view class="product_details_box_goumai_box" @click="goumaiFun">
						立即购买
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		goods_detail
	} from '@/api/home.js'
	export default {
		data() {
			return {
				openid: '',
				res: '',
				show: false,
				num: 1,
				id: ''
			};
		},
		onLoad(e) {
			this.id = e.id;
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data;
					this.goods_detailFun({
						openid: res.data,
						id: e.id
					});
				},
				fail: () => {
					uni.reLaunch({
						url: '/pages/login/login'
					});
				}
			});
		},
		methods: {
			valChange(e) {

			},
			goumaiFun() {
				this.show = !this.show;
				uni.navigateTo({
					url: `/pages/home/confirmAnOrder/confirmAnOrder?id=${this.id}&total=${this.num}`
				})
			},
			open() {},
			close() {
				this.show = !this.show
			},
			async goods_detailFun(up) {
				let data = await goods_detail(up);
				let content = data.content + '';
				content = content.replace(/data-lazy/g, "src");
				content = content.replace(/style="/g, 'style="width:100%;');
				data.content = content;
				this.res = data;
			}
		}
	}
</script>

<style lang="scss">
	.popup_box {
		width: 100%;
		height: 400rpx;
		background-color: #fff;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		position: relative;

		.popup_box_goods {
			padding: 20rpx;
			width: 100%;
			display: flex;
			align-items: flex-end;
			position: absolute;
			top: -60rpx;
			border-bottom: 2rpx solid #dfdfdf;


			image {
				background-color: #fff;
				width: 150rpx;
				box-shadow: 0 0 20rpx #ccc;
			}



			.popup_box_goods_text {
				width: 300rpx;
				height: 152rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				padding: 0 0 0 20rpx;


				span {
					font-size: 30rpx;
					font-weight: 600;
					text-wrap: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}

				p {
					color: #ff1200;
				}
			}
		}

		.number {
			margin-top: 150rpx;
			display: flex;
			padding: 0 20rpx;
			justify-content: space-between;
			align-items: center;
		}

		.product_details_box_goumai_box {
			width: 100%;
			height: 80rpx;
			background: linear-gradient(3deg, #ff3232, #ff3232, #ff8719);
			display: flex;
			align-items: center;
			justify-content: center;
			color: #F2F2F2;
		}


	}


	.product_details {
		width: 100%;
		display: flex;
		flex-direction: column;

		.product_details_box {
			width: 100%;

			.product_details_box_top {
				width: 100%;
				height: 450rpx;

				image {
					width: 100%;
					height: 450rpx;
				}
			}

			.product_details_box_title {
				width: 690rpx;
				height: 192rpx;
				background: #fff;
				box-shadow: 0px 0px 20rpx 0px #F2F2F2;
				border-radius: 20rpx;
				margin: 10rpx auto;
				position: relative;
				z-index: 1;
				padding: 30rpx;

				.product_details_box_title_name {
					width: 100%;
					height: 40rpx;
					color: #2b2f38;
				}

				.product_details_box_title_marketprice {
					padding: 20rpx 0;
					font-size: 26rpx;
					display: flex;
					justify-content: space-between;
					color: #b0b0b0;

					p {
						color: #ff1200;
					}
				}
			}

			.product_details_box_commodity_details {
				width: 100%;
				padding: 0 40rpx;
				margin-bottom: 140rpx;

				.product_details_box_commodity_details_box {}
			}

			.product_details_box_goumai {
				width: 100%;
				height: 130rpx;
				background-color: #fff;
				position: fixed;
				bottom: 0;
				padding: 20rpx 30rpx;

				.product_details_box_goumai_box {
					width: 100%;
					height: 100%;
					background: linear-gradient(3deg, #ff3232, #ff3232, #ff8719);
					border-radius: 100rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					color: #F2F2F2;
				}
			}


		}
	}
</style>